最近折腾nginx有点多,大家忍忍,今天我们要讲的是docker下构建Nginx为例,来讲解docker下镜像的制作。Nginx的编译参数参考 Nginx 1.18.0 安装脚本
我们docker用的基础镜像用CENTOS: docker pull centos 获得。
新建一个目录 ,然后新建一个文件 Dockerfile,内容如下
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
# Version: 0.0.1 FROM centos:7 MAINTAINER 92k "admin@92k.xin" RUN yum -y update RUN yum -y install gcc gcc-c++ wget make file openssl openssl-devel WORKDIR /web/soft/ RUN wget http://nginx.org/download/nginx-1.18.0.tar.gz -P /web/soft/ RUN wget https://ftp.pcre.org/pub/pcre/pcre-8.44.tar.gz -P /web/soft/ RUN wget http://www.zlib.net/zlib-1.2.11.tar.gz -P /web/soft/ RUN tar -zxf nginx-1.18.0.tar.gz RUN tar -zxf pcre-8.44.tar.gz RUN tar -zxf zlib-1.2.11.tar.gz RUN cd nginx-1.18.0 &&./configure --prefix=/web/nginx --with-http_ssl_module --with-http_v2_module --with-http_realip_module --with-http_addition_module --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_auth_request_module --with-http_random_index_module --with-http_secure_link_module --with-http_degradation_module --with-http_slice_module --with-http_stub_status_module --with-stream --with-stream_ssl_module --with-stream_ssl_preread_module --with-pcre=../pcre-8.44/ --with-zlib=../zlib-1.2.11/ && make&& make install EXPOSE 80/tcp 443/tcp CMD ["/web/nginx/sbin/nginx"] RUN echo "daemon off;" >> /web/nginx/conf/nginx.conf RUN rm -rf /web/nginx/conf/*.default |
这个编译过程少了 openssl部分,替代的是系统的openssl,用原来的那个,一直会编译不过,不知道为啥,就是openssl这里编译不过去。
上述问题找了了,少了一个 perl(2020年11月10日)
docker build -t nginx:v0.0.1
编译完成后 我们可以通过docker images 看到我们的nginx的镜像了。
我们先跑起来:
docker run –name Nginx -p 80:80 -p443:443 -d nginx:v0.0.1
恭喜自己成功编译好了Nginx 并顺利工作。
有点遗憾,我们的Nginx大小524MB,有点大,我们需要瘦身,近期写。